*
set more off
eststo clear
use temp1,clear
egen naf2yr = group(naf2 year)
global depvar "llaborpty"
global depvar_d1  "llaborpty_d1"
*
****************************
*FIRST TABLE: REDUCED FORM *
****************************
*NAIVE
*FE
eststo: xtreg  $depvar shock3intens  i.naf2yr, robust cluster(firmid) fe i(firmid)
*FD
eststo: reg 	$depvar_d1  shock6intens i.naf2yr, robust cluster(firmid)
*FE+FD
eststo: xtreg   $depvar_d1  shock6intens  i.naf2yr, robust cluster(firmid)  fe i(firmid)
*INV AND MATERIALS CONTROLED
*FE
eststo: xtreg  $depvar shock3intens linv lmatraw i.naf2yr, robust cluster(firmid) fe i(firmid)
*FD
eststo: reg 	$depvar_d1  shock6intens linv_d1 lmatraw_d1 i.naf2yr, robust cluster(firmid)
*FE+FD
eststo: xtreg   $depvar_d1  shock6intens linv_d1 lmatraw_d1 i.naf2yr, robust cluster(firmid)  fe i(firmid)
*
log using $DIRLOG/Replication/tab-ReducedForm.txt, text replace
*
set linesize 255
esttab, keep(shock* linv* lmatraw*) b(%4.3f) se(%4.3f) r2 starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)  tex  title() label
esttab, keep(shock* linv* lmatraw*) compress r2 starlevels(c 0.1 b 0.05 a 0.01)  b(%4.3f) se(%4.3f)
*output the results in a tex file directly inputable in the text
esttab using $DIRLOG/Replication/tab-ReducedForm_input.tex, b(%4.3f) se(%4.3f)  starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)    ///
nocons keep(shock* linv* lmatraw*)  label tex substitute(\_ \_)  fragment replace nodepvars nonumbers nomtitles nogaps nolines eqlabels(none)
eststo clear
log close



***With leads and lags***
set more off
eststo clear
use temp1,clear
egen naf2yr = group(naf2 year)
global depvar "llaborpty"
global depvar_d1  "llaborpty_d1"
*
****************************
*FIRST TABLE: REDUCED FORM *
****************************
*NAIVE
*FE
eststo: xtreg  $depvar shock3intens_l2 shock3intens_l1 shock3intens shock3intens_f1 shock3intens_f2 i.naf2yr, robust cluster(firmid) fe i(firmid)
*FD
eststo: reg 	$depvar_d1  shock6intens_l2 shock6intens_l1 shock6intens shock6intens_f1 shock6intens_f2 i.naf2yr, robust cluster(firmid)
*FE+FD
eststo: xtreg   $depvar_d1  shock6intens_l2 shock6intens_l1 shock6intens shock6intens_f1 shock6intens_f2  i.naf2yr, robust cluster(firmid)  fe i(firmid)
*INV AND MATERIALS CONTROLED
*FE
eststo: xtreg  $depvar shock3intens_l2 shock3intens_l1 shock3intens shock3intens_f1 shock3intens_f2 linv lmatraw i.naf2yr, robust cluster(firmid) fe i(firmid)
regsave using temp_leadlag_tab7_FE,replace
*FD
eststo: reg 	$depvar_d1  shock6intens_l2 shock6intens_l1 shock6intens shock6intens_f1 shock6intens_f2 linv_d1 lmatraw_d1 i.naf2yr, robust cluster(firmid)
regsave using temp_leadlag_tab7_FD,replace
*FE+FD
eststo: xtreg   $depvar_d1  shock6intens_l2 shock6intens_l1 shock6intens shock6intens_f1 shock6intens_f2 linv_d1 lmatraw_d1 i.naf2yr, robust cluster(firmid)  fe i(firmid)
regsave using temp_leadlag_tab7_FDFE,replace
*
log using $DIRLOG/Replication/tab-ReducedForm_robleadlag.txt, text replace
*
set linesize 255
****************************************************************************
esttab, keep(shock* linv* lmatraw*) b(%4.3f) se(%4.3f) r2 starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)  tex  title() label
esttab, keep(shock* linv* lmatraw*) compress r2 starlevels(c 0.1 b 0.05 a 0.01)  b(%4.3f) se(%4.3f)
*output the results in a tex file directly inputable in the text
esttab using $DIRLOG/Replication/tab-ReducedForm_robleadlag_input.tex, b(%4.3f) se(%4.3f)  starlevels({$^c$} 0.1 {$^b$} 0.05 {$^a$} 0.01)    ///
nocons keep(shock* linv* lmatraw*)  label tex substitute(\_ \_) fragment replace nodepvars nonumbers nomtitles nogaps nolines eqlabels(none)
eststo clear
log close
